package cn.afactory.tygz.ui.activities;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.AttributeSet;
import android.view.View;

import com.tendcloud.tenddata.TCAgent;

import cn.afactory.tygz.R;
import cn.afactory.tygz.common.TopicType;
import cn.afactory.tygz.ui.base.BaseFragmentActivity;
import cn.afactory.tygz.ui.base.utils.SPUtils;
import cn.afactory.tygz.ui.fragments.TopicHotListFragment;

/**
 * Created by Kenneth on 15/9/17.
 */
public class TopicHotListActivity extends BaseFragmentActivity {

    private TopicHotListFragment mFragment;
    private int mType;
    private int mPageIndex = 0;
    public void setPageIndex(int index) {
        mPageIndex = index;
    }

    private void initTitleBar() {
        if(mType == TopicType.RECOMMAND){
            setTitleText("推荐话题");
        } else {
            setTitleText("热门话题");
        }
        showBackView();
    }

    /**
     * 跳转到热门和推荐列表
     * @param context
     * @param type
     */
    public static void gotoTopicList(Context context,int type){
        Intent intent = new Intent(context,TopicHotListActivity.class);
        intent.putExtra(SPUtils.EXTRA_TYPE,type);
        context.startActivity(intent);
    }

    @Override
    public View onCreateView(String name, Context context, AttributeSet attrs) {
        return super.onCreateView(name, context, attrs);
    }

    @Override
    public void onResume() {
        super.onResume();
        TCAgent.onResume(this);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.ac_fragment);

        mType = getIntent().getIntExtra(SPUtils.EXTRA_TYPE,-1);

        initview();
        initTitleBar();
    }

    private void initview() {
        mFragment = new TopicHotListFragment(mType);
        if (mFragment != null) {
            addFragment(mFragment);
        } else {
            finish();
        }
    }

    private void addFragment(Fragment fragment) {
        getSupportFragmentManager().beginTransaction()
                .add(R.id.fl_layout, fragment, "" + fragment.getClass())
                .commit();
    }
}
